/**
 * 
 */
package com.williamoneil.charts.client.util;

import java.util.HashMap;
import java.util.Map;

import com.williamoneil.charts.client.data.ColorThemeData;

/**
 * @author gudipati
 *
 */
public class Colors {

	private static final String WHITE = "rgba(255,255,255,1)";
	private static final String BLACK = "rgba(0,0,0,1)";
	private static final String GREEN = "rgba(0,254,0,1)";
	private static final String BLUE = "rgba(0,0,254,1)";
	private static final String RED = "rgba(254,0,0,1)";
	private static final String PURPLE = "rgba(160,76,254,1)";
	private static final String GRAY = "rgba(128,128,128,1)";
	
	private static final String RED_DOWNTICK = "rgba(208,0,48,1)";
	private static final String BLUE_UPTICK = "rgba(0,102,204,1)";
	private static final String BLUE_HIGHLIGHT_UPTICK = "rgba(52,190,248,1)";
	private static final String RED_HIGHLIGHT_UPTICK = "rgba(254,122,237,1)";

//	private static final String MAJOR_GRID = "rgba(128,128,128,1)";
	private static final String MINOR_GRID = "rgba(128,128,128,0.75)";
	
	private static final String EPS_ORANGE = "rgba(252,105,1)";
	private static final String REV_GREEN = "rgba(8,152,0)";
	
	private static boolean useLightTheme = true;
	public static boolean isLightTheme() {
		return useLightTheme;
	}
	
	public static void changeColorTheme(boolean isLightTheme) {
		useLightTheme = isLightTheme;
		colorTheme = null;
	}
	
	private static ColorThemeData colorTheme = null; 
	public static ColorThemeData  getColorTheme() {
		if(colorTheme == null) {
			if(useLightTheme) {
				colorTheme = getLightTheme();
			} else {
				colorTheme = getDarkTheme();
			}
		}
		
		return colorTheme;
	}
	
	private static final ColorThemeData getDarkTheme() {
		final ColorThemeData theme = new ColorThemeData();
		final Map<Integer, String> colorMap = new HashMap<Integer, String>();
		theme.setColorMap(colorMap);
		
		colorMap.put(ColorEntityType.CHART_BACKGROUND.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.CHART_BORDER.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.MINOR_GRIDLINE.getId(), Colors.MINOR_GRID);
		colorMap.put(ColorEntityType.MAJOR_GRIDLINE.getId(), Colors.MINOR_GRID);
		colorMap.put(ColorEntityType.GRIDLINE_LABEL.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.TICK_UP.getId(), Colors.BLUE_UPTICK);
		colorMap.put(ColorEntityType.TICK_DOWN.getId(), "rgba(204,0,153,1)");
		colorMap.put(ColorEntityType.TICK_NEUTRAL.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.TRACKPRICE_LINE.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.TICK_HIGHLIGHTED_UP.getId(), Colors.BLUE_HIGHLIGHT_UPTICK);
		colorMap.put(ColorEntityType.TICK_HIGHLIGHTED_DOWN.getId(), Colors.RED_HIGHLIGHT_UPTICK);
		
		colorMap.put(ColorEntityType.PRICE_MOVING_AVG_1.getId(), Colors.RED);
		colorMap.put(ColorEntityType.PRICE_MOVING_AVG_2.getId(), Colors.GREEN);
		colorMap.put(ColorEntityType.BENCHMARK_LINE.getId(), "rgba(70,155,231)");
		colorMap.put(ColorEntityType.VOLUME_MOVING_AVG.getId(), Colors.RED);
		
		colorMap.put(ColorEntityType.TICK_HILOW_LABEL.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.RS_LINE.getId(), Colors.PURPLE);
		
		colorMap.put(ColorEntityType.TRACKPRICE_PRICE_PRICE_INDICATOR_FILL.getId(), Colors.GRAY);
		colorMap.put(ColorEntityType.TRACKPRICE_PRICE_PRICE_INDICATOR_TEXT.getId(), Colors.BLACK);
		
		colorMap.put(ColorEntityType.EPS_LINE.getId(), Colors.EPS_ORANGE);
		colorMap.put(ColorEntityType.REV_LINE.getId(), Colors.REV_GREEN);
		return theme;
	}
	
	private static final ColorThemeData getLightTheme() {
		final ColorThemeData theme = new ColorThemeData();
		final Map<Integer, String> colorMap = new HashMap<Integer, String>();
		theme.setColorMap(colorMap);
		
		colorMap.put(ColorEntityType.CHART_BACKGROUND.getId(), Colors.WHITE);
		colorMap.put(ColorEntityType.CHART_BORDER.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.MINOR_GRIDLINE.getId(), Colors.MINOR_GRID);
		colorMap.put(ColorEntityType.MAJOR_GRIDLINE.getId(), Colors.MINOR_GRID);
		colorMap.put(ColorEntityType.GRIDLINE_LABEL.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.TICK_UP.getId(), Colors.BLUE_UPTICK);
		colorMap.put(ColorEntityType.TICK_DOWN.getId(), Colors.RED_DOWNTICK);
		colorMap.put(ColorEntityType.TICK_NEUTRAL.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.TRACKPRICE_LINE.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.TICK_HIGHLIGHTED_UP.getId(), Colors.BLUE_HIGHLIGHT_UPTICK);
		colorMap.put(ColorEntityType.TICK_HIGHLIGHTED_DOWN.getId(), Colors.RED_HIGHLIGHT_UPTICK);
		
		colorMap.put(ColorEntityType.PRICE_MOVING_AVG_1.getId(), Colors.RED);
		colorMap.put(ColorEntityType.PRICE_MOVING_AVG_2.getId(), Colors.GREEN);
		colorMap.put(ColorEntityType.BENCHMARK_LINE.getId(), Colors.BLUE);
		colorMap.put(ColorEntityType.VOLUME_MOVING_AVG.getId(), Colors.RED);
		
		colorMap.put(ColorEntityType.TICK_HILOW_LABEL.getId(), Colors.BLACK);
		colorMap.put(ColorEntityType.RS_LINE.getId(), Colors.PURPLE);

		colorMap.put(ColorEntityType.TRACKPRICE_PRICE_PRICE_INDICATOR_FILL.getId(), Colors.GRAY);
		colorMap.put(ColorEntityType.TRACKPRICE_PRICE_PRICE_INDICATOR_TEXT.getId(), Colors.BLACK);
		
		colorMap.put(ColorEntityType.EPS_LINE.getId(), Colors.EPS_ORANGE);
		colorMap.put(ColorEntityType.REV_LINE.getId(), Colors.REV_GREEN);
		return theme;
	}
}
